package com.szqhyxj.youxiangju.sys.components.view.popview;

import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.szqhyxj.youxiangju.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * XiaoPanYu
 * on 2018/11/26
 */
public class ConsumePatternDialog extends BaseDialog {

    @BindView(R.id.equipment_content)
    TextView equipmentContent;
    @BindView(R.id.equipment_refund)
    LinearLayout equipmentRefund;
    @BindView(R.id.shortcut_refund)
    LinearLayout shortcutRefund;
    TextView titleDevice;
    TextView titleOnline;
    TextView timetitle;
    TextView navigationbar_title;
    TextView contentonline;
    private ImageView img;
    private ISharePlatformListener listener;


    public interface ISharePlatformListener {

        void onEquipmentRefund(View view);

        void onShortcutRefund(View view);
    }

    public void setISharePlatformListener(ISharePlatformListener listener) {
        this.listener = listener;
    }

    public ConsumePatternDialog(Context context) {
        super(context);
        /** 放到setContentView 后设置才有效 设置dialog 宽 为 屏幕宽度 */
        WindowManager m = window.getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = window.getAttributes();
        p.width = d.getWidth(); //设置dialog的宽度为当前手机屏幕的宽度
        window.setAttributes(p);
        p.height = d.getHeight() / 2;
        setGravity(Gravity.BOTTOM);
    }

    @Override
    public View initDialogView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.popview_consume_pattern, null);
        ButterKnife.bind(this, view);
        img = view.findViewById(R.id.top_view_right);
        titleDevice = view.findViewById(R.id.titledevice);
        titleOnline = view.findViewById(R.id.titleonline);
        timetitle = view.findViewById(R.id.timetitle);
        navigationbar_title = view.findViewById(R.id.navigationbar_title);
        contentonline = view.findViewById(R.id.contentonline);
        equipmentRefund.setOnClickListener(this);
        shortcutRefund.setOnClickListener(this);
        img.setOnClickListener(this);
        return view;
    }

    public void setOnClickListener(ISharePlatformListener listener) {
        this.listener = listener;
    }

    @OnClick({R.id.equipment_refund, R.id.shortcut_refund, R.id.top_view_right})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.equipment_refund:
                if (listener != null) {
                    listener.onEquipmentRefund(view);
                }
                break;
            case R.id.shortcut_refund:
//                if (listener != null) {
//                    listener.onShortcutRefund(view);
//                }
                break;
            case R.id.top_view_right:
                dismiss();
                break;
        }
    }


    public void setTitleDevice(String title) {
        this.titleDevice.setText(title);
    }

    public void setTitleOnline(String title) {
        this.titleOnline.setText(title);
    }

    public void setEquipmentContent(String content) {
        this.equipmentContent.setText(content);
    }

    public void setEquipmentContentColor(int color) {
        this.equipmentContent.setTextColor(color);
    }

    public void setnavigationbarTitle(String title){
        this.navigationbar_title.setText(title);
    }

    public void setcontentonline(String content){
        this.contentonline.setText(content);
    }
}
